﻿@model ThaireInvestmentWeb.Models.InstructionFormModel
@{
    ViewBag.Title = "InstructionForm";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {
        applyValidateDate();
        $("#TradeDate,#SettlementDate").datepicker(
      {
          dateFormat: 'dd/mm/yy',
          isBuddhist: true,
          showOn: 'button',
          showAnim: 'fadeIn',
          changeMonth: true,
          changeYear: true,
          showButtonPanel: true,
          buttonImage: '@Url.Content("~/Content/images/Calendar.png")',
          onSelect: function (dateText, inst)
          {
              var selectData = $("#FinancialInstrument option:selected").val();
              if (selectData == '1')
              {
                  $('#TradeDate').val(dateText);
              }
          }
      });
        
        $("#FinancialInstrument").change(function ()
        {
            var selectData = $("#FinancialInstrument option:selected").val();
          
            if (selectData != '') {

                 $.ajax({
                     url: "@Url.Action("GetAssetClass", "Instruction")" + "?instrumentID=" + selectData ,
                   type: 'POST',
                   success: function (data)
                   {
                       $('#FinancialInstrumentAssetClass').empty();
                       var optionDef = $('<option />');
                       optionDef.attr('value', '').text('----Select---');
                       $('#FinancialInstrumentAssetClass').append(optionDef);
                       $(data).each(function ()
                       {
                        
                           var option = $('<option />');
                           option.attr('value', this.AssetClassID).text(this.AssetClassEN);

                           $('#FinancialInstrumentAssetClass').append(option);
                       });

                     

                     

                       return false;
                   }
               });
            } else
            {
                $('#FinancialInstrumentAssetClass').empty();
            }
        });
        

    });

   
    function del(key)
    {
        showConfirm("ต้องการลบหรือไม่ ?", function ()
        {
            $("#DeleteInstructionKey").val(key);
            var form = $('#mainForm');
           // var fakeSubmit = genFakeSubmitBtn("ConfirmBtn", form)
            form.submit();
          //  fakeSubmit.remove();
           // event.preventDefault();
            closeConfirm();
        });
        return false;


        //if (confirm('ต้องการลบหรือไม่')) {
           
        //    return true;
        //} else {

        //    return false;
        //}
    }
</script>

<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instruction > <a href="instructionList">Instruction</a> > Instruction Header
            </div>
        </td>
    </tr>
</table>
<table class="tableheader" width="100%" border="0" align="center" cellpadding="0"
    cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">Instruction Form
        </td>
    </tr>
</table>
<table width="100%" border="0" align="center">
    <tr>
        <td>
            @Html.ValidationSummary(true)
        </td>
    </tr>

</table>
@using (Html.BeginForm("InstructionForm", "Instruction", FormMethod.Post, new { id="mainForm"}))
{
    

                <table width="100%" border="0" align="center" cellspacing="2">
                    <!--DWLayoutTable-->
                    <tr>
                        <td width="551" height="31">&nbsp;
                        </td>
                        <td width="236" valign="top">
                            <div align="right">
                                Create by :
                            </div>
                        </td>
                        <td width="10">&nbsp;
                        </td>
                        <td width="139">Create Time
                        </td>
                    </tr>
                    <tr>
                        <td width="551" height="31">&nbsp;
                        </td>
                        <td width="236" valign="top">
                            <div align="right">
                                Approved by :
                            </div>
                        </td>
                        <td width="10">&nbsp;
                        </td>
                        <td width="139">Approved Time
                        </td>
                    </tr>
                    <tr>
                        <td height="31">&nbsp;
                        </td>
                        <td>
                            <div align="right">
                                Update by :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>Update Time
                        </td>
                    </tr>
                </table>


                <table class="tableform" width="100%" border="0" align="center" cellspacing="2">

                    <tr>
                        <td width="212">
                            <div align="right">
                                To:
                            </div>
                        </td>
                        <td width="8">&nbsp;
                        </td>
                        <td width="246">
                            @Html.TextBoxFor(x => x.To)
                        </td>
                        <td width="188" align="right">
                            <div align="right">
                                Status:
                            </div>
                        </td>
                        <td width="6">&nbsp;
                        </td>
                        <td width="208">
                            @Html.TextBoxFor(x => x.Status, new { disabled = "disabled" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Attention :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.Attn)
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                E-Mail :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.Email)
                        </td>
                        <td>
                            <div align="right">
                                Company <span class="error">*</span> :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.DropDownListFor(x => x.Company, Model.CompanyList)
                            @Html.ValidationMessageFor(x => x.Company)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Financial Instrument <span class="error">*</span> :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.DropDownListFor(x => x.FinancialInstrument, Model.FinancialInstrumentList)
                            @Html.ValidationMessageFor(x => x.FinancialInstrument)
                        </td>
                        <td>
                            <div align="right">
                                Tel No. :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.ComTelNo, new { disabled = "disabled" })
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div align="right">
                                Asset Class <span class="error">*</span> : 
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.DropDownListFor(x => x.FinancialInstrumentAssetClass, Model.FinancialInstrumentAssetClassList)
                         
                        </td>
                         <td>
                            <div align="right">
                                Fax No. :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.ComFaxNo, new { disabled = "disabled" })
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div align="right">
                                Trade Date <span class="error">*</span> :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.TradeDate, new { need_validateDate=true, @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(Model.TradeDate) })
                           (Ex.31/12/2014) @Html.ValidationMessageFor(x => x.TradeDate)

                        </td>
                       <td>
                            <div align="right">
                                E-Mail :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.ComEmail, new { disabled = "disabled" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Settlement Date <span class="error">*</span> :
                            </div>
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>
                            @Html.TextBoxFor(x => x.SettlementDate, new { need_validateDate=true, @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(Model.SettlementDate) })
                            (Ex.31/12/2014) @Html.ValidationMessageFor(x => x.SettlementDate)
                        </td>
                        
                    </tr>
                    <tr>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;
                        </td>
                    </tr>
                </table>


                <table width="95%" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center">
                                <input type="submit" id="BtnGetSelection" name="BtnGetSelection" value="Get Selection" />
                                &nbsp;&nbsp;&nbsp;
                            </div>
                        </td>
                    </tr>

                </table>



                <div style="width: 100%; overflow: auto;">

                    @if (Model.TransactionDataGridAdapterList != null)
                    {
                        var grid = new WebGrid(source: Model.TransactionDataGridAdapterList, ajaxUpdateContainerId: "grid", rowsPerPage: 25, canSort: false);
                       
                        @grid.GetHtml(htmlAttributes: new { id = "grid" }, tableStyle: "tablelist", headerStyle: "headertable", displayHeader: @Model.TransactionDataGridAdapterList.Count > 0,
                              columns:  ThaireInvestmentWeb.Util.WebUtil.GridSelect(grid,Html,Model.InstrumentType));


                    }


                </div>
                <a name="grid-anchor"></a>
                <script type="text/javascript">
                    $(function () {
                        $('th a, tfoot a').live('click', function () {
                            $(this).attr('href', '#grid-anchor');
                        });
                    });
                </script>

                    if (Model.TransactionDataGridAdapterList != null && Model.TransactionDataGridAdapterList.Count > 0)
                    {
                <table width="95%" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center">
                                <input type="submit" id="BtnAdd" name="BtnAdd" value=" Add " />
                            </div>
                        </td>
                    </tr>
                </table>
                    }
                <div style="width: 100%; border: 1px; overflow: auto;">

                    @if (Model.SelectedTransactionDataGridAdapterList != null && Model.SelectedTransactionDataGridAdapterList.Count > 0)
                    {
                        var grid = new WebGrid(source: Model.SelectedTransactionDataGridAdapterList, ajaxUpdateContainerId: "gridselected", rowsPerPage: 25, canSort: false);
                        @grid.GetHtml(htmlAttributes: new { id = "gridselected" }, tableStyle: "tablelist", headerStyle: "headertable", displayHeader: @Model.SelectedTransactionDataGridAdapterList.Count > 0,
            columns:   ThaireInvestmentWeb.Util.WebUtil.GridSelected(grid,Html,Url,Model.InstrumentType));


                    }


                </div>


                <table width="95%" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center">
                                @if (Model.SelectedTransactionDataGridAdapterList != null && Model.SelectedTransactionDataGridAdapterList.Count > 0)
                                {
                                    <input id="BtnSave" type="button"  name="BtnSave" value="Submit" class="button" need-confirm="true"  />
                                }
                                @if (Model.Updatemode)
                                {
                                      
                                    <input type="submit" name="BtnExportExcelInitial" id="BtnExportExcelInitial" value="Initial Export" class="button" />
                                    
                                    <span>&nbsp;&nbsp;</span>
                                    
                                     <input type="submit" name="BtnExportExcel" id="BtnExportExcel" value="Non Initial Export" class="button" />
                                    
                                    <span>&nbsp;&nbsp;</span>
                                    <input type="button" name="Submit223" value=" Approve" class="button" need-confirm="true" confirm-text="ยืนยันการอนุมัติ ?" />
                                    <span>&nbsp;&nbsp;</span>
                                    <input type="button" name="Submit224" value=" Back " class="button" onclick="self.location.href = 'ManageInstruction'" />
                                }
                            </div>
                        </td>
                    </tr>
                </table>

                @Html.HiddenFor(x => x.Updatemode);
                @Html.HiddenFor(x => x.DeleteInstructionKey);




}
